function CheckLogin(mobile, password) {

    if (!mobile) {
        $('.mobile_error').css('display', 'block');
        return;
    }
    if (!password) {
        $('.pwd_error').css('display', 'block');
    }
}

$(function () {
    $('.ui-button').click(function () {
        // 获取登录信息
        event.preventDefault();
        mobile = $('.mobile').val();
        password = $('.password').val();

        // 校验注册信息
        CheckLogin(mobile, password);

        //提交信息
        var params = {
            "mobile": mobile,
            "password": password,
            "csrfmiddlewaretoken": $("*[name='csrfmiddlewaretoken']").val(),
        };
        $.ajax({
            url: "/login/",
            type: "post",
            data: JSON.stringify(params),
            headers: {
                'X-CSRFToken': $.cookie('csrftoken')
            },
            async: false,
            contentType: "application/json",
            success: function (resp) {
                if (resp.errno == "0") {
                    alert('登录成功');
                    window.location = "/";
                } else {
                    if (resp.errno == '1112') {
                        data = resp.errmsg;
                        $('.mobile_error').html(data);
                        $('.mobile_error').show()
                    } else if (resp.errno == '1114') {
                        data = resp.errmsg;
                        $('.pwd_error').html(data);
                        $('.pwd_error').show()
                    } else if (resp.errno == '1115') {
                        data = resp.errmsg;
                        $('.pwd_error').html(data);
                        $('.pwd_error').show()
                    }

                }
            },
        });
    });
});
